import { IState, SubMachine } from "./State"

export class StateMachine<Tkey> {
    mainMachine: SubMachine<Tkey> = new SubMachine()
    get currState(): IState<Tkey> {
        return this.mainMachine.currState
    }
    startWith(name: Tkey) {
        this.mainMachine.defaultState = name
        this.mainMachine.transitTo(name)
    }
    registState(state) {
        this.mainMachine.add(state)
    }
    deregisterState(id: Tkey) {
        this.mainMachine.remove(id)
    }
    transit(name: Tkey) {
        this.mainMachine.transitTo(name)
    }
    update(dt: number) {
        this.mainMachine.update(dt)
    }

}
